package com.ms.index;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.ms.common.model.BusOrder;
import com.ms.common.util.MsUtility;

public class TotalController extends Controller{

	/**
	 * 按订单进行统计分析
	 */
	public void costTotal(){
		Map paraMap=getParaMap();
		Page<BusOrder> page=BusOrder.dao.totalPageConditions(paraMap,getParaToInt("page"),getParaToInt("rows") );
		renderJson(MsUtility.TransToEasyUiPage(page));
	}
	
	public void listBus(){
		Map paraMap=getParaMap();
		Page<BusOrder> page=BusOrder.dao.totalBusPageConditions(paraMap,getParaToInt("page"),getParaToInt("rows") );
		renderJson(MsUtility.TransToEasyUiPage(page));
	}
	
	public void listOilc(){
		Map paraMap=getParaMap();
		Page<BusOrder> page=BusOrder.dao.totalOilPageConditions(paraMap,getParaToInt("page"),getParaToInt("rows") );
		List<BusOrder> orderLst=page.getList();
		double total_fee_num=0.00;
		for (int i = 0; i < orderLst.size(); i++) {
			BusOrder order=orderLst.get(i);
			Map orderMap=new HashMap<>();
			total_fee_num+=order.getDouble("fee_sum");
			if(i==0){
				orderMap.put("total_fee_num", total_fee_num);
				orderMap.put("curr_rank", 0);
				orderMap.put("curr_use_fee", 0);
			}else{
				orderMap.put("total_fee_num", total_fee_num);
				orderMap.put("curr_rank", order.getDouble("rank_num")-orderLst.get(i-1).getDouble("rank_num"));
				orderMap.put("curr_use_fee", orderLst.get(i-1).getDouble("fee_sum"));
				
			}
			order._setAttrs(orderMap);
		}
		renderJson(MsUtility.TransToEasyUiPage(page));
	}
	
	
	
}
